package com.dnzx.controller.web;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.dnzx.framework.result.ResultUtils;
import org.dnzx.framework.result.domain.Result;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.dnzx.model.ArticleBO;
import com.dnzx.service.IArticleService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

@RestController
@RequestMapping("/web/article")
@Api(value = "/web/article",description="文章管理",produces=MediaType.APPLICATION_JSON_VALUE)
public class WebArticleController {
	
	@Resource
	private IArticleService articleService;
	
	/**
	 * 查看
	 * @param id
	 * @return
	 */
	@GetMapping("/get/{id}")
	@ApiOperation(value = "/get/{id}",notes = "查看",httpMethod = "GET",produces=MediaType.APPLICATION_JSON_VALUE)
	public Result get(@ApiParam(value = "id") @PathVariable("id") Long id, HttpServletRequest request) {
		try {
			ArticleBO articleBO = this.articleService.get(id);
			return ResultUtils.returnSuccess("SUCCESS >>> ", articleBO);
		}catch(Exception e) {
			return ResultUtils.returnError(e.getMessage());
		}
	}
	
	/**
	 * 查询 - 分页
	 * @param articleBO
	 * @return
	 */
	@PostMapping("/queryList")
	@ApiOperation(value="/queryList",notes="查询 - 分页：不用传参数",httpMethod="POST",produces=MediaType.APPLICATION_JSON_VALUE)
	public Result queryList(@ApiParam(value = "实体") @RequestBody ArticleBO articleBO, HttpServletRequest request) {
		try {
			List<ArticleBO> articleBOList = this.articleService.queryList(articleBO);
			return ResultUtils.returnSuccess("SUCCESS >>> ", articleBOList);
		}catch(Exception e) {
			e.printStackTrace();
			return ResultUtils.returnError(e.getMessage());
		}
	}

}
